/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {string[]}
 */
var binaryTreePaths = function(root) {
    const res = []
    let path = []
    const dfs = function(node) {
        // 找到叶子节点，记录
        if(node.left === null && node.right === null) {
            res.push(path.join('->'))
            return
        }
        path.push(node.val)
        if(node.left) {
            dfs(node.left)
        }
        if(node.right) {
            dfs(node.right)
        }
        path.pop()
    }
    dfs(root)
    return res
};